home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libgphoto2-2 / linux-hotplug / usbcam.console next >
Encoding:
Text File  |  2009-01-07  |  1.6 KB  |  47 lines

  1. #!/bin/bash
  2. # $Id: usbcam.console 9668 2006-12-18 16:31:44Z hun $
  3. #
  4. # /etc/hotplug/usb/usbcam
  5. #
  6. # Sets up newly plugged in USB camera so that the user who owns
  7. # the console according to pam_console can access it from user space
  8. #
  9. # Note that for this script to work, you'll need all of the following:
  10. # a) a line in the file /etc/hotplug/usermap that corresponds to the 
  11. #    camera you are using. You can get the correct lines for all cameras 
  12. #    supported by libgphoto2 by running
  13. #              $ print-camera-list usb-usermap usbcam
  14. # b) a setup using pam_console creates the respective lock files
  15. #    containing the name of the respective user. You can check for that
  16. #    by executing "echo `cat /var/{run,lock}/console.lock`" and 
  17. #    verifying the appropriate user is mentioned somewhere there.
  18. # c) a Linux kernel supporting hotplug and usbdevfs
  19. # d) the hotplug package (http://linux-hotplug.sourceforge.net/)
  20. #
  21. # In the usermap file, the first field "usb module" should be named 
  22. # "usbcam" like this script.
  23.  
  24. if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
  25. then
  26.     # New code, using lock files instead of copying /dev/console permissions
  27.     # This also works with non-gdm logins (e.g. on a virtual terminal)
  28.     # Idea and code from Nalin Dahyabhai <nalin@redhat.com>
  29.     CONSOLEOWNER=""
  30.     for conlock in \
  31.         /var/run/console.lock \
  32.         /var/run/console/console.lock \
  33.         /var/lock/console.lock
  34.     do
  35.         if [ -f "$conlock" ]; then
  36.         CONSOLEOWNER=`cat $conlock`
  37.         fi
  38.     done
  39.     if [ -n "$CONSOLEOWNER" ]
  40.     then
  41.         chmod 0000 "${DEVICE}"
  42.         chown "$CONSOLEOWNER" "${DEVICE}"
  43.         chmod 0600 "${DEVICE}"
  44.     fi
  45. fi
  46.